#! /bin/bash

shopt -s extglob
if [ "$GOROOT" == "" ]; then
	echo GOROOT is not set.
fi

wsdir=$(dirname $BASH_SOURCE)
export GOPATH=$(readlink -f $wsdir/..)
bindir=$GOPATH/bin
export PATH=$PATH:$bindir


# Optional settings:
# export taskedconf=$GOPATH/config
export testdata=$GOPATH/test
export testdir=$testdata/testdir


# Setup workspace:

function ensuredir {
	if [ $1 -a ! -d $1 ]; then
		if [ -e $1 ]; then
			rm -rf $1
		fi
		mkdir -p $1
	fi
}
srcdir=$GOPATH/src
ensuredir $bindir
ensuredir $srcdir

if [ $taskedconf ]; then
	ensuredir $taskedconf
fi

rm -rf $testdata/!(tls|settings)

go get code.google.com/p/gopam
if [ ! -d src/code.google.com/p/tasked ]; then
	if [ -e src/code.google.com/p/tasked ]; then
		rm -rf src/code.google.com/p/tasked
	fi
	go get code.google.com/p/tasked
fi

if [ -e $bindir/tsk ]; then
	rm -rf $bindir/tsk
fi
cp $wsdir/tsk $bindir
